home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
NOVA - For the NeXT Workstation
/
NOVA - For the NeXT Workstation.iso
/
Documents
/
NeXTAnswers
/
appkit.747
< prev
next >
Wrap
Text File
|
1992-02-06
|
3KB
|
78 lines
{\rtf0\ansi{\fonttbl\f0\fnil Times-Roman;\f1\fmodern Ohlfs;\f2\fswiss Helvetica;}
\paperw13040
\paperh10800
\margl120
\margr120
{\colortbl\red0\green0\blue0;}
\pard\tx960\tx1920\tx2880\tx3840\tx4800\tx5760\tx6720\tx7680\tx8640\tx9600\f0\b0\i0\ul0\fs28 appending text font\
\
Q: How do I append text to a text object, such that the new text has a different font?\
\
A: First of all, make sure that the text object can contain multiple fonts. Send the following message to your text object:\
\
\f1\fs22 id myText;\
...\
[myText setMonoFont:NO];\
...\
\f0\fs28 \
Then, use the following code snippet to append the text, select the text, and change its font:\
\
\f1\fs22 id myText;\
int length;\
\
...\
length = [myText textLength];\
[myText setSel:length:length]; // put an empty selection at the end of the text\
\fc0 [myText replaceSel:"some new text"]; // add some text\
[myText setSel:(length-1):[self textLength]]; // select the newly added text\
[myText setSelFont:
\pard\tx620\tx1240\tx1860\tx2480\tx3100\tx3720\tx4340\tx4980\tx5600\tx6220\fc0 [Font newFont:"Symbol" size:
\pard\tx960\tx1920\tx2880\tx3840\tx4800\tx5760\tx6720\tx7680\tx8640\tx9600\fc0 24.0
\pard\tx620\tx1240\tx1860\tx2480\tx3100\tx3720\tx4340\tx4980\tx5600\tx6220\fc0 ]
\pard\tx960\tx1920\tx2880\tx3840\tx4800\tx5760\tx6720\tx7680\tx8640\tx9600\fc0 ]; // change its font\
...\
\f0\fs28 \
The following code snippet
\b will not work
\b0 due to the way in which setSelFont:, and replaceSel: interact:\
\
\f1\fs22 id myText;\
int length;\
\
...\
length = [myText textLength];\
[myText setSel:length:length]; // put an empty selection at the end of the text\
[myText setSelFont:
\pard\tx620\tx1240\tx1860\tx2480\tx3100\tx3720\tx4340\tx4980\tx5600\tx6220\fc0 [Font newFont:"Symbol" size:
\pard\tx960\tx1920\tx2880\tx3840\tx4800\tx5760\tx6720\tx7680\tx8640\tx9600\fc0 24.0
\pard\tx620\tx1240\tx1860\tx2480\tx3100\tx3720\tx4340\tx4980\tx5600\tx6220\fc0 ]
\pard\tx960\tx1920\tx2880\tx3840\tx4800\tx5760\tx6720\tx7680\tx8640\tx9600\fc0 ]; // change the font\
[myText replaceSel:"some new text"]; // add some text\
...\
\f0\fs28 \
To avoid some of the flashing that may occur to the text object while selecting and modifying the font programmatically, you should perform a
\b disableDisplay
\b0 on the window containing the text object before selecting and modifying the text. After the modifications you should then
\b reenableDisplay
\b0 on the window and
\b display
\b0 the text object. See NeXTanswers appkit.710 for more information about
\b disableDisplay.
\b0 \
\
For more information about appending text to a text object see NeXTanswer appkit.396.\
\
QA747\
\
Valid for 1.0\
Valid for 2.0\
\